home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Shout3Ddemo
/
Shout3d_runtime
/
codebase
/
custom_nodes
/
WavySceneEffect.java
< prev
Wrap
Text File
|
2000-09-21
|
3KB
|
108 lines
/**
Company: Eyematic Interfaces
Project: Shout3D 2.0 Sample Code
Class: InvertSceneEffect
Date: March 23, 2000
Description: A simple example of a PostRenderEffect that makes the scene have an animated waviness run through it.
(C) Copyright Eyematic Interfaces, Inc. - 1997-2000 - All rights reserved
*/
package custom_nodes;
import shout3d.core.*;
import shout3d.*;
import java.awt.Graphics;
/**
* InvertSceneEffect
*
* @author Dave Westwood
*/
public class WavySceneEffect extends PostRenderEffect {
// Amplitude of the wave in pixels
final public IntField waveAmplitude = new IntField(this, "waveAmplitude", Field.ANY, 30);
// Length of the wave in pixels
final public IntField waveLength = new IntField(this, "waveLength", Field.ANY, 60);
// Velocity of animation of the wave, in pixels per second.
final public IntField crawlVelocity = new IntField(this, "crawlVelocity", Field.ANY, 10);
/**
* Constructs a default InvertSceneEffect node.
*/
public WavySceneEffect(){}
int[] horizOffset = null;
double startClockT = -1;
int oldAmplitude = -1;
int oldWavelength = -1;
int rowShift, toPixel, rowFirst, rowLast;
public void filter(Graphics offScreenGraphics, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
if (surface_pixel_bits == null)
return;
// Store these to avoid any nastiness happening from field values that change
// while we are filtering.
int curWaveAmplitude = waveAmplitude.getValue();
int curWaveLength = waveLength.getValue();
int curCrawlVelocity = crawlVelocity.getValue();
// Allocate an array of horizontal offsets for each of the rows within a waveLength's cycle
if (horizOffset == null || oldAmplitude != curWaveAmplitude ||
oldWavelength != curWaveLength){
horizOffset = new int[curWaveLength];
for (int i = 0; i < curWaveLength; i++){
horizOffset[i] = (int) (curWaveAmplitude * Math.sin( 2 * 3.14159 * ((float)i) / curWaveLength));
}
oldAmplitude = curWaveAmplitude;
oldWavelength = curWaveLength;
}
// How much time has passed since beginning? Need this for crawl which is
// velocity based.
if (startClockT == -1){
startClockT = getViewer().getClock().getAbsoluteTime();
}
double deltaT = getViewer().getClock().getAbsoluteTime() - startClockT;
toPixel = 0;
for (int row=0; row<deviceHeight; row++){
rowShift = horizOffset[ ((int)(row + (float)curCrawlVelocity * deltaT)) % curWaveLength ];
rowFirst = toPixel;
rowLast = toPixel + deviceWidth - 1;
if (rowShift > 0){
for (int col=0; col<deviceWidth; col++){
if (col + rowShift < deviceWidth){
surface_pixel_bits[toPixel] = surface_pixel_bits[toPixel+rowShift];
}
else {
surface_pixel_bits[toPixel] = surface_pixel_bits[rowLast];
}
toPixel++;
}
}
else if (rowShift < 0){
toPixel += deviceWidth - 1;
for (int col=deviceWidth-1; col >= 0; col--){
if (col + rowShift >= 0){
surface_pixel_bits[toPixel] = surface_pixel_bits[toPixel+rowShift];
}
else {
surface_pixel_bits[toPixel] = surface_pixel_bits[rowFirst];
}
toPixel--;
}
toPixel += deviceWidth + 1;
}
else {
// rowShift is 0, skip to next row.
toPixel += deviceWidth;
}
}
}
}